<!--
 * @Author: Wayne 13235388225@163.com
 * @Date: 2023-10-09 14:42:14
 * @LastEditors: Wayne 13235388225@163.com
 * @LastEditTime: 2023-10-09 16:19:36
 * @FilePath: \Jkc-app-front-new\src\views\partnerManagement\partnerManagement.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <div class="view-title">合伙人申请管理</div>
    <!-- <el-button type="primary" @click="handlerAdd">添加</el-button> -->

    <el-table
      :data="applicationTableData"
      :header-cell-style="{
        borderColor: '#F0F0F0',
        height: '51px',
        background: '#F0F0F0',
        color: '#333',
      }"
      :row-style="{ height: '51px' }"
      :cell-style="{ borderColor: '#F0F0F0' }"
      style="width: 100%; margin-top: 20px"
    >
      <el-table-column
        prop="name"
        label="姓名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="mobile"
        label="手机号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="user_id"
        label="用户id"
        align="center"
      ></el-table-column>

      <el-table-column label="支付状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.is_pay == 1"
            ><el-tag type="warning">未支付</el-tag></span
          >
          <span v-else-if="scope.row.is_pay == 2"
            ><el-tag type="success">已支付</el-tag></span
          >
          <span v-else-if="scope.row.is_pay == 4"
            ><el-tag type="danger">退款</el-tag></span
          >
        </template>
      </el-table-column>

      <el-table-column
        prop="money"
        label="支付金额"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="out_trade_no"
        label="out_trade_no"
        width="260"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="status" label="审核状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0"
            ><el-tag type="warning">申请中</el-tag></span
          >
          <span v-else-if="scope.row.status == 1"
            ><el-tag type="success">通过申请</el-tag></span
          >
          <span v-else-if="scope.row.status == 2"
            ><el-tag type="danger">拒绝申请</el-tag></span
          >
        </template>
      </el-table-column>
      <el-table-column prop="created_at" label="创建时间" align="center">
      </el-table-column>
      <el-table-column prop="updated_at" label="更新时间" align="center">
      </el-table-column>
      <el-table-column
        prop="reason"
        label="加入原因"
        align="center"
      ></el-table-column>
      <el-table-column fixed="right" label="操作" width="160" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="handlerExamine(scope.row)"
            :disabled="scope.row.status == 1"
            v-permission="['partnerApplication:audit']"
            >审核</el-button
          >
          <!--              <el-button @click="handleEdit(scope.row)" type="text" size="small">修改</el-button>-->
          <el-button
            type="text"
            size="small"
            @click="handlerDelete(scope.row)"
            v-permission="['partnerApplication:delete']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <div class="page_box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNow"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 审核弹窗 -->
    <el-dialog
      title="审核合伙人"
      :visible.sync="dialogVisibleExamine"
      :close-on-click-modal="false"
      width="30%"
    >
      <div class="dialog_examine_box">
        <div>审核状态：</div>
        <div>
          <el-select
            v-model="examineValue"
            placeholder="请选择审核状态"
            @change="handlerChangeExamine"
          >
            <el-option
              v-for="item in examineOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialogExamine">取 消</el-button>
        <el-button type="primary" @click="sureDialogExamine">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getAppAgentRecordList,
  examineAppAgentRecordFront,
  deleteAppAgentRecord,
} from "@/api/partnerManagement.js";

export default {
  name: "PartnerApplication",
  data() {
    return {
      pageNow: 1,
      pageSize: 10,
      total: null,
      applicationTableData: [],
      examineUserId: "",
      examineOutTradeNo: "",
      examineStatus: "",
      dialogVisibleExamine: false,
      examineValue: "",
      examineOptions: [
        {
          value: "1",
          label: "通过申请",
        },
        {
          value: "2",
          label: "拒绝申请",
        },
      ],
      deleteId: "",
    };
  },
  mounted() {
    this.getAppAgentRecordList(0);
  },
  methods: {
    // 查询全部合伙人申请记录
    getAppAgentRecordList() {
      getAppAgentRecordList({
        page_now: this.pageNow,
        page_size: this.pageSize,
      }).then((res) => {
        if (res.code == 1) {
          this.applicationTableData = res.data;
          this.total = res.page_info.total_count;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 合伙人申请审核
    examineAppAgentRecordFront() {
      examineAppAgentRecordFront({
        user_id: this.examineUserId,
        out_trade_no: this.examineOutTradeNo,
        status: this.examineStatus,
      }).then((res) => {
        if (res.code == 1) {
          this.$message.success(res.msg);
          this.getAppAgentRecordList();
          this.dialogVisibleExamine = false;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 删除合伙人申请记录
    deleteAppAgentRecord() {
      deleteAppAgentRecord({
        ids: this.deleteId,
      }).then((res) => {
        if (res.code == 1) {
          this.$message.success(res.msg);
          this.getAppAgentRecordList();
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 添加
    handlerAdd() {},

    handlerChangeExamine() {
      this.examineStatus = this.examineValue;
    },

    // 审核
    handlerExamine(val) {
      this.examineUserId = val.user_id;
      this.examineOutTradeNo = val.out_trade_no;
      this.dialogVisibleExamine = true;
    },

    // 修改
    // handleEdit(val) { },

    // 删除
    handlerDelete(val) {
      this.deleteId = val.id;
      this.$confirm("是否确定删除该条合伙人申请记录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteAppAgentRecord();
        })
        .catch(() => {});
    },

    // 审核弹窗确定
    sureDialogExamine() {
      this.examineAppAgentRecordFront();
    },

    // 审核弹窗取消
    cancelDialogExamine() {
      this.dialogVisibleExamine = false;
      this.examineStatus = "";
    },

    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.getAppAgentRecordList();
    },
    handleCurrentChange(val) {
      this.pageNow = val;
      this.pageSize = 10;
      this.getAppAgentRecordList();
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog_examine_box {
  display: flex;
  align-items: center;
}
</style>
